package com.hunttown.mes.common.message;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSource;
import org.springframework.util.Assert;

/**
 * created by hunttown on 2017/7/27
 */
public class Messages implements ApplicationContextAware {
    private static MessageSource messageSource;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        messageSource = applicationContext.getBean("messageSource", MessageSource.class);
        Assert.notNull(messageSource, "must has an named 'messageSource' bean");
    }

    public static String message(String key, Object... args) {
        return messageSource.getMessage(key, args, null);
    }
}